import { JSONValue, ToolCallPayload } from "ai"

// import { } from './tools/basic'
// import { } from './tools/view'
// import { } from './tools/vision'
import { toolsCallback } from "./chat-tools-data"

export const applyToolCall = (toolCallPayload: ToolCallPayload): { tool_call_id: string; function_name: string; tool_call_result: JSONValue; } | null => {
    for (const toolCall of toolCallPayload.tools) {
        const { name: funcName, arguments: funcArgs } = toolCall.func
        if (toolsCallback.hasOwnProperty(funcName)) {
            return {
                tool_call_id: toolCall.id,
                function_name: toolCall.func.name,
                tool_call_result: toolsCallback[funcName].call(null, funcArgs)
            }
        }
    }
    return null
}